$(function() {
   //获取token
   var token = localStorage.token;
   //加载地址列表
   $.ajax({
       type: "get",
       url: domain.test + "/getaddresslist",
       beforeSend: function (xhr) {
           xhr.setRequestHeader("token",token);
       },
       success: function (response) {
           if(response.data.rtnCode===200) {
               var addressList = response.data.data;
               console.log(addressList);
               $(".addressList").html(template("addressList",{addressList:addressList}));
           }
       }
   }); 
   //设置默认地址
   $(".addressList").on("click",".adminAdd",function(e) {
       e.stopPropagation();
     var status = parseInt( $(this).find(".hidden").val());
     if(status===1) {
         return false;
     }
     var addressId = parseInt($(".addressItem").attr("data-addressId"));
     var regionId = parseInt($(".addressItem").attr("data-regionId"));
     var contact = $(".person").attr("data-contcat");
     var mobile = $(".tel").attr("data-mobile");
     var address = $(".address").attr("data-address");
     var region =  $(".address").attr("data-region");
     $.ajax({
         type: "post",
         url: domain.test + "/address",
         data: {
            id:addressId,
            contact:contact,
            mobile:mobile,
            address:address,
            regionId:regionId,
            default:"true"
         },
         beforeSend: function (xhr) {
            xhr.setRequestHeader("token",token);
         },
         success: function (response) {
             console.log(response);
             if(response.data.rtnCode===200) {
                //  location.reload();
             }
         }
     });
   });
});